#include "sht20.h"

uint16_t sht20_read(uint8_t cmd)
{
			uint16_t val = 0;
			uint8_t sht20_buff[2] = {0};
			HAL_I2C_Master_Transmit(&hi2c1,sht20_address_write,&cmd,1,100);
			HAL_I2C_Master_Receive(&hi2c1,sht20_address_read,sht20_buff,2,100);
			val = (sht20_buff[0]<<8)|sht20_buff[1];
			val &= ~0x01;
			return val;
}

void sht20_data(float *t,float *rh)
{
			uint16_t t_tempnum=0,rh_tempnum=0;
			
			t_tempnum=sht20_read(t_cmd);
			rh_tempnum=sht20_read(rh_cmd);
			
			*rh= -6.0+125.0*((float)rh_tempnum/65536.0);
			*t = -46.85+175.72*((float)t_tempnum/65536.0);
}